package com.myrule;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import com.netflix.loadbalancer.RetryRule;
import com.netflix.loadbalancer.RoundRobinRule;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author yangshen
 * @date 2019/8/27 23:34
 */
@Configuration
public class MySelfRule {

    //自定义负载均衡规则：
    @Bean
    public IRule myRule(){
        //return new RoundRobinRule();    //轮询
        //return new RandomRule();        //随机
        //return new RetryRule();         //先按照轮询，如果获取服务失败后则重试，指定时间后将不再请求失败的服务
        return new Random_YS();           //自定义算法：1.轮询；2.每台机器执行五次后随机；
    }
}
